<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>

</head>
<body>

  <!--
  getElementById():根据id属性值获取，返回单个对象
  getElementByTagName():根据标签名获取，返回对象数组
  getElementByName():根据name属性获取值，返回对象数组
  getElementByClassName:根据class属性获取值，返回对象数组
   -->
  <img id="img" src="../img/on.gif"/><br>
  <div class="cls">JS</div>
  <div class="cls">Java</div>

  <input type="checkbox" name="hobby"/>唱歌
  <input type="checkbox" name="hobby"/>跳舞
  <input type="checkbox" name="hobby"/>rap
  <input type="checkbox" name="hobby"/>篮球

  <script type="text/javascript">
    //根据id获取img对象
    var img = document.getElementById("img");
    alert(img);

    //根据标签名获取
    var divs = document.getElementsByTagName("div");
    alert(divs);
    alert(divs.length);

    //根据name获取
    var hobbys = document.getElementsByName("hobby");
    alert(hobbys);
  </script>

</body>
</html>